//
//  Avatar+UserNameView.swift
//  ShiZhe
//
//  Created by 陈卿伟 on 16/9/6.
//  Copyright © 2016年 陈卿伟. All rights reserved.
//

import UIKit

class Avatar_UserNameView: UIView {
    var cameraButton:UIButton!
    var userNameTF:UITextField!
    var beganButton:UIButton!
    var messageLabel:UILabel!
    override init(frame: CGRect) {
        cameraButton = UIButton()
        userNameTF = UITextField()
        beganButton = UIButton()
        messageLabel = UILabel()
        super.init(frame: frame)
        self.createRedBG()
        self.createCameraButton()
        self.createUserNameTF()
        self.createMessageLabel()
        self.createBeganButton()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        userNameTF.resignFirstResponder()
    }
    
    //红色的幕布  和 提示文字
    func createRedBG(){
        let redView = UIView(frame: CGRect(x: 0,y: 0,width: WidthAPP,height: 55*SCALEH))
        redView.backgroundColor = UIColor.redColor()
        self.addSubview(redView)
        
        let hintLabel = UILabel(frame: CGRect(x: 20*SCALEW,y: 0,width: WidthAPP-40*SCALEW,height: 55*SCALEH))
        hintLabel.text = "最后一步，当你被选为精选，总要让别人看到你的头像和昵称吧😊"
        hintLabel.numberOfLines = 2
        hintLabel.font = BaseFunc.getLightFont(14)
        hintLabel.textAlignment = .Left
        hintLabel.textColor = UIColor.whiteColor()
        self.addSubview(hintLabel)
    }
    
    //创建设置头像的按钮
    func createCameraButton(){
        cameraButton.frame = CGRect(x: 138*SCALEW, y: 78*SCALEH, width: 100*SCALEW, height: 100*SCALEW)
        cameraButton.backgroundColor = Theme.GrayColor
        cameraButton.layer.cornerRadius = 50*SCALEW
        cameraButton.setImage(UIImage(named: "camera"), forState: UIControlState())
        self.addSubview(cameraButton)
    }
    
    //创建昵称输入框
    func createUserNameTF(){
        userNameTF.frame = CGRect(x: 32*SCALEW, y: 198*SCALEH, width: 311*SCALEW, height: 39*SCALEH)
        userNameTF.textAlignment = .Center
        userNameTF.placeholder = "请输入昵称"
        userNameTF.keyboardType = .Default
        userNameTF.font = BaseFunc.getSystemFont(14.5)
        userNameTF.backgroundColor = UIColor.whiteColor()
        userNameTF.leftView = UIView(frame: CGRect(x: 0,y: 0,width: 10,height: 1))
        userNameTF.leftViewMode = .Always
        userNameTF.layer.borderWidth = 1
        userNameTF.layer.borderColor = BaseFunc.createCustomColor(240, b: 240, g: 240, a: 1).CGColor
        userNameTF.layer.cornerRadius = 5
        self.addSubview(userNameTF)
    }
    
    //创建提示文字
    func createMessageLabel(){
        messageLabel.frame = CGRect(x: 0, y: 259*SCALEH, width: WidthAPP, height: 17*SCALEH)
        messageLabel.font = BaseFunc.getCustomFont(14)
        messageLabel.textAlignment = .Center
        messageLabel.text = "如果没有填写，系统将会为您配置默认的用户名和头像"
        messageLabel.textColor = Theme.GrayColor
        self.addSubview(messageLabel)
    }
    
    
    //创建开始三人行之旅按钮
    func createBeganButton(){
        beganButton.frame = CGRect(x: 33*SCALEW, y: 290*SCALEH, width: 309*SCALEW, height: 50*SCALEH)
        beganButton.titleLabel?.font = BaseFunc.getCustomFont(18)
        beganButton.setTitle("开启三人行之旅", forState: UIControlState())
        beganButton.backgroundColor = Theme.YellowColor
        beganButton.layer.cornerRadius = 5
        self.addSubview(beganButton)
    }

}









